struct Texture {
	corona::Image* image;
	GLuint handle;
	string name;
	int width, height;


	Texture (string filename) {
		handle = null;
		image = corona::OpenImage( filename.c_str(), corona::PF_R8G8B8A8 );
		
		if (!image)
			return;

		width = image->getWidth();
		height = image->getHeight();

		glGenTextures(1, &handle);
		load();
		name = filename;
	}

	

	~Texture () {
		unload();
		delete image;
	}

	void activate () {

		if (handle == null) {
			glDisable (GL_TEXTURE_2D);
			glColor4d (1.0, 1.0, 0.0, 1.0);
			return;
		}
		
		glEnable (GL_TEXTURE_2D);
		glBindTexture (GL_TEXTURE_2D, handle);
	};
	//

	void load () {
		if (handle == null)
			return;
		
		glBindTexture (GL_TEXTURE_2D, handle);

		glPixelStorei   (GL_PACK_ALIGNMENT, 4);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->getPixels() );
	};
	//	

	void unload () {
		if (handle != null)
			glDeleteTextures (1, &handle);
		
		handle = null;
	};
	//

};